const axios = require('axios')
export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: ' 炉管家 - 锅炉的事，就找炉管家',
    htmlAttrs: {
      lang: 'en'
    },
    meta: [{
        charset: 'utf-8'
      },
      {
        name: 'viewport',
        content: 'width=device-width, initial-scale=1'
      },
      {
        name: 'baidu-site-verification',
        content: 'codeva-WH4KlTjrg3'
      },
      {
        hid: 'keywords',
        name: 'keywords',
        content: '炉管家,宁波厚德能源科技有限公司,特设助手,锅炉物联网,高效落实两个责任,安全阀检验,修锅炉,智慧锅炉,特种设备物联网,锅炉运维,工业物联网平台'
      },
      {
        hid: 'description',
        name: 'description',
        content: '宁波厚德能源科技有限公司官网 - 通过与物联网技术的融合，实现了对锅炉设备的远程监控、数据分析和智能化运维管理，旗下有炉管家、特配商城、特设助手、云耐压试验&特监之眼等产品'
      },
    ],
    link: [{
        rel: 'icon',
        type: 'image/x-icon',
        href: '/index/logo.svg'
      },
      {
        rel: 'stylesheet',
        href: "https://fonts.googleapis.com/css?family=Noto+Sans+SC:100,300,400,500,700,900"
      }
    ],
    script: [
      { src: 'https://hm.baidu.com/hm.js?043001b8b9f659c1cbd2d9b5d46b71e0' }
    ]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css                                                                                                                     
  css: [
    'normalize.css',
    'element-ui/lib/theme-chalk/index.css',
    '@/theme/index.css',
    '@/assets/css/index.scss',
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    { src: "@/util/main" },
    {
      src: '@/util/rsaEncrypt',
      ssr: false
    },
    '@/plugins/element-ui',
    '@/plugins/common',
    '@/plugins/axios',
    {
      src: '~/plugins/baidu'
    }
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    '@nuxtjs/style-resources',
    '@nuxtjs/axios',
    '@nuxtjs/proxy',
    '@nuxtjs/sitemap'
  ],

    router: {
    // 全部跳转到斜杠结尾的地址
    trailingSlash: true
  },
  // axios: {
  //   proxy: true, // 开启代理
  //   prefix: '/api', // 表示给请求url加个前缀 /api -> 本地调试 http://localhost:3000/api/
  // },
  // proxy: {
  //   '/api': {
  //     target: 'http://127.0.0.1:9999', // 允许跨域的服务器地址
  //     // ws:true, // 是否启用websockets
  //     pathRewrite: {
  //       '^/api': '' // 路径重新
  //     }
  //   }
  // },
  styleResources: {
    scss: '@/assets/css/variables.scss'
  },
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    transpile: [/^element-ui/],
    extractCSS: true,
    optimization: {
      splitChunks: {
        cacheGroups: {
          styles: {
            name: 'styles',
            test: /\.(css|vue)$/,
            chunks: 'all',
            enforce: true
          }
        }
      }
    }
  },

  serverMiddleware: [
    '@/plugins/middleware',
  ],

  render: {
    compressor: true,
    static: {
      setHeaders(res) {
        res.setHeader('X-Frame-Options', 'SAMEORIGIN');
        res.setHeader('Referrer-Policy', 'origin');
        res.setHeader('X-XSS-Protection', '1; mode=block');
        res.setHeader('X-Content-Type-Options', 'nosniff');
        res.setHeader(
          'Content-Security-Policy',
          "default-src *; \
          style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; \
          script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.baidu.com https://*.bdstatic.com; \
          img-src * data:; \
          worker-src * blob:; \
          font-src 'self' https://fonts.gstatic.com data:;"
        );
        res.setHeader('X-Download-Options', 'noopen');
        res.setHeader('X-Permitted-Cross-Domain-Policies', 'master-only');
      },
    },
  },

  generate: {
    async routes() {
      const newsResponse = await axios.get('https://www.lukeeper.com/protal-api/client/news/page?current=1&size=100');
      
      const newsRoutes = newsResponse.data.data.records.flatMap(news => [
        '/mobile/news/' + news.id + '/',
        '/pc/news/' + news.id + '/'
      ]);
      
      return newsRoutes;
    },
  },

  sitemap: {
    hostname: 'https://www.lukeeper.com',
    gzip: true,
    exclude: [
      '/pc/news/',
      '/mobile/news/',
      '/pc/admin/'
    ],
    routes: [
      '/pc/news/1/',
      '/pc/news/10/',
      '/pc/news/11/',
      '/pc/news/14/',
      '/pc/news/16/',
      '/pc/news/17/',
      '/pc/news/18/',
      '/pc/news/19/',
      '/pc/news/20/',
      '/pc/news/21/',
      '/pc/news/22/',
      '/pc/news/23/',
      '/pc/news/24/',
      '/pc/news/25/',
      '/pc/news/26/',
      '/pc/news/27/',
      '/pc/news/28/',
      '/pc/news/29/',
      '/pc/news/30/',
      '/pc/news/31/',
      '/pc/news/32/',
      '/mobile/news/1/',
      '/mobile/news/10/',
      '/mobile/news/11/',
      '/mobile/news/14/',
      '/mobile/news/16/',
      '/mobile/news/17/',
      '/mobile/news/18/',
      '/mobile/news/19/',
      '/mobile/news/20/',
      '/mobile/news/21/',
      '/mobile/news/22/',
      '/mobile/news/23/',
      '/mobile/news/24/',
      '/mobile/news/25/',
      '/mobile/news/26/',
      '/mobile/news/27/',
      '/mobile/news/28/',
      '/mobile/news/29/',
      '/mobile/news/30/',
      '/mobile/news/31/',
      '/mobile/news/32/',
    ]
  }
}
